#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve() {
    string s;
    cin >> s;
    int ans = 4;
    char t = '1';
    for(auto ch : s) {
        if(ch == '0'){
            ch = '9';
            ch++;
        }
        int t1 = ch - t;
        ans += abs(t1);
        t = ch;
    }
    cout << ans << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}